# LeaderBoardManager.loadPlayerCenteredScores
# 功能描述
查询当前用户相近的其他用户成绩(上下X位)。
# 参数
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
leaderboardId | string | 是 | 排行榜ID | |
collection | string | public | 否 | 榜单类型,有效值为 friends 或 public ;当 collection 参数为 friends 时需要在隐私协议中添加好友关系且用户授权好友关系方可调用成功;为 public 时不需要授权 |
maxCount | number | 5 | 否 | 限制只能使用 [1,25] 之间的数字 |
callback | Object | 否 | 接口调用结果回调 |
callback:
属性 | 类型 | 默认值 | 必填 | 说明 |
---|---|---|---|---|
success | function | 否 | 接口调用成功的回调函数 | |
fail | function | 否 | 接口调用失败的回调函数 | |
complete | function | 否 | 接口调用结束的回调函数(成功/失败都会执行) |
success回调返回的数据: 同 LeaderBoardManager.loadLeaderboardScores success回调返回的数据格式相同。
# 错误
1025、104、103错误码,在collection参数为"friends"时可能遇到,若遇到1025错误码,请参照权限说明部分修改小游戏后台配置。
错误码 | 错误信息 | 说明 |
---|---|---|
500001 | 排行榜 ID 未找到 | 排行榜 ID 不存在 |
500002 | 排行榜参数错误 | 排行榜 ID 与游戏不匹配 |
500201 | leaderboardId 为空 | 提示传入正确的排行榜 ID |
500200 | maxCount 参数错误 | 请检查 maxCount 是否在 [1,25] 区间 |
103 | 用户未授权使用其好友关系信息 | 调用需要好友关系权限的 API 时,用户没有授权使用好友信息则返回该错误码 |
104 | 用户未通过隐私协议 | 调用需要好友关系权限的 API 时,用户没有通过隐私协议则返回该错误码 |
1025 | 小游戏没有申明使用好友关系信息 | 开发者在后台没有在隐私协议中申明使用好友关系,调用需要好友关系权限的 API 时会返回此错误码;请参照权限说明部分修改小游戏后台配置。 |
# 示例代码
tapLeaderboard.loadPlayerCenteredScores({
leaderboardId: "your_leaderboardId", // 排行榜ID
collection: "friends", // 好友榜
maxCount: 10, // 最大返回数量,有效取值范围[1,25]
callback: {
onSuccess: function(res) {
console.log("loadPlayerCenteredScores success:", JSON.stringify(res, null, 2));
},
onFailure: function(code, message) {
console.error(`loadPlayerCenteredScores failed: code=${code}, message=${message}`);
}
}
});